<table width="100%"><tr><td width="20%">
<a href="../index.html">&lt; index</a><br />
<a href="../system/index.html">&lt; 3. System layer</a>
</td><td width="60%">
<p align="center">
=====================================<br />
3.1 High precision time functions<br />
=====================================<br />
</p></td><td width="20%">
</td></tr></table>
<style type="text/css">
.code { color:#444444; background-color:#EEEEEE;}
pre { color:#444444; background-color:#EEEEEE;}
table.param td { border : 1px solid #000000; }
th { background-color: #44BBFF; color: #FFFFFF }
table.none td { border : 0 }
</style>
These are functions specifically aimed at real time game development.<br />
The setFps function allows you to limit the number of frames per second.<br/>
If a frame is rendered faster than expected, the <a href="../console/console_flush.html">TCOD_console_flush</a> function will wait so that the frame rate never exceed this value.<br />
You can call this function during your game initialization.<br />
You can dynamically change the frame rate. Just call this function once again.<br />
<p class="code"><pre>
C++ : static void TCODSystem::setFps(int val)
C   : void TCOD_sys_set_fps(int val)
Py  : sys_set_fps(val)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>val</td><td>Maximum number of frames per second. 0 means unlimited frame rate.</td></tr>
</table>
Example :<br />
<p class="code"><pre>
C++ : TCODSystem::setFps(25);
C   : TCOD_sys_set_fps(25);
Py  : libtcod.sys_set_fps(25)
</pre></p>
<br />
The getFps function returns the actual number of frames rendered during the last second.<br/>
This value is updated every second.<br />
<p class="code"><pre>
C++ : static int TCODSystem::getFps()
C   : int TCOD_sys_get_fps()
Py  : sys_get_fps()
</pre></p>
Example :<br />
<p class="code"><pre>
C++ : int fps = TCODSystem::getFps();
C   : int fps = TCOD_sys_get_fps();
Py  : fps = libtcod.sys_get_fps()
</pre></p>
<br />
The getLastFrameLength function return the length in seconds of the last rendered frame.<br/>
You can use this value to update every time dependant object in the world.<br />
<p class="code"><pre>
C++ : static float TCODSystem::getLastFrameLength()
C   : float TCOD_sys_get_last_frame_length()
Py  : sys_get_last_frame_length()
</pre></p>
Example : moving an objet at 5 console cells per second<br />
<p class="code"><pre>
C++ : float x=0,y=0; // object coordinates
      x += 5 * TCODSystem::getLastFrameLength();
      TCODConsole::root->putChar((int)(x),(int)(y),'@');
C   : float x=0,y=0;
      x += 5 * TCOD_sys_get_last_frame_length();
      TCOD_console_put_char(NULL,(int)(x),(int)(y),'@');
Py  : x=0.0
      y=0.0
      x += 5 * libtcod.sys_get_last_frame_length()
      libtcod.console_put_char(0,int(x),int(y),'@')
</pre></p>
<br />
The sleepMilli function allows you to stop the program execution for a specified number of milliseconds.<br/>
<p class="code"><pre>
C++ : static void TCODSystem::sleepMilli(uint32 val)
C   : void TCOD_sys_sleep_milli(uint32 val)
Py  : sys_sleep_milli(val)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>val</td><td>Number of milliseconds before the function returns.</td></tr>
</table>
Example :<br />
<p class="code"><pre>
C++ : TCODSystem::sleepMilli(50);
C   : TCOD_sys_sleep_milli(50);
Py  : libtcod.sys_sleep_milli(50)
</pre></p>
<br />
This function returns the number of milliseconds since the program has started.<br/>
<p class="code"><pre>
C++ : static uint32 TCODSystem::getElapsedMilli()
C   : uint32 TCOD_sys_elapsed_milli()
Py  : sys_elapsed_milli()
</pre></p>
Example :<br />
<p class="code"><pre>
C++ : uint32 milli=TCODSystem::getElapsedMilli();
C   : uint32 milli=TCOD_sys_elapsed_milli();
Py  : milli=libtcod.sys_elapsed_milli()
</pre></p>
<br />
This function returns the number of seconds since the program has started.<br/>
<p class="code"><pre>
C++ : static float TCODSystem::getElapsedSeconds()
C   : float TCOD_sys_elapsed_seconds()
Py  : sys_elapsed_seconds()
</pre></p>
Example :<br />
<p class="code"><pre>
C++ : float seconds = TCODSystem::getElapsedSeconds();
C   : float seconds = TCOD_sys_elapsed_seconds();
Py  : seconds = libtcod.sys_elapsed_seconds()
</pre></p>
